package com.tianya.portal.common.config;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;

@Component
public class AsposeConfig {

    /**
     * 注册aspose.word
     */
    @PostConstruct
    public void initAsposeWord() throws Exception {
        // 构造一个注册信息
        Class<?> zzljClass = Class.forName("com.aspose.words.zzlj");
        Constructor<?> constructors = zzljClass.getDeclaredConstructors()[0];
        constructors.setAccessible(true);
        Object instance = constructors.newInstance("zzZgL", "zzYRe");
        Field zzWcV = zzljClass.getDeclaredField("zzWcV");
        zzWcV.setAccessible(true);
        zzWcV.set(instance, 1);

        // 把注册信息放到 效验类中
        Class<?> zzYVAClass = Class.forName("com.aspose.words.zzZv0");
        Field zzcC = zzYVAClass.getDeclaredField("zzcC");
        zzcC.setAccessible(true);
        ArrayList<Object> zzcCValue = new ArrayList<>();
        zzcCValue.add(instance);
        zzcC.set(null, zzcCValue);

        // 生成文档会掉这个来判断
        Class<?> zzXQoClass = Class.forName("com.aspose.words.zzNc");
        Field zzW5e = zzXQoClass.getDeclaredField("zzW5e");
        zzW5e.setAccessible(true);
        zzW5e.set(null, 128);
        Field zzNS = zzXQoClass.getDeclaredField("zzNS");
        zzNS.setAccessible(true);
        zzNS.set(null, false);
    }
}
